package com.depth.viewer.manager
{
	import com.depth.viewer.container.definition.IWidgetContainerDefinition;
	import com.depth.viewer.utils.Hashtable;
	import com.depth.viewer.widget.IBaseWidget;
	import com.depth.viewer.widget.IWidget;
	import com.depth.viewer.widget.definition.IWidgetDefinition;
	
	public class WidgetRegistry implements IWidgetRegistry
	{
		public function WidgetRegistry()
		{
			_widgetDefinitionMap = new Hashtable();
			_widgetMap = new Hashtable();
		}
		
		private var _widgetDefinitionMap:Hashtable;
		private var _widgetMap:Hashtable;
		
		
		
		
		public function registerWidgetDefinition(widgetDefinition:IWidgetDefinition):void
		{
			this._widgetDefinitionMap.add(widgetDefinition.id,widgetDefinition);
		}
		
		public function unRegisterWidgetDefinition(widgetDefinitionId:String):void
		{
			this._widgetDefinitionMap.remove(widgetDefinitionId);
		}
		
		public function getRegistedWidgetDefinition(widgetDefinitionId:String):IWidgetDefinition
		{
			return this._widgetDefinitionMap.find(widgetDefinitionId);
		}
		
		public function getRegistedWidgetDefinitions():Array
		{
			var defNames:Array = this._widgetDefinitionMap.getKeySet();
			var defs:Array = [];
			for each(var defName:String in defNames){
				var def:IWidgetDefinition = this._widgetDefinitionMap.find(defName);
				defs.push(def);
			}
			return defs;
		}
		
		public function registerWidget(widget:IBaseWidget):void
		{
			this._widgetMap.add(widget.widgetId,widget);
		}
		
		public function unRegisterWidget(widgetId:String):void
		{
			this._widgetMap.remove(widgetId);
		}
		
		public function getRegistedWidget(widgetId:String):IBaseWidget
		{
			return this._widgetMap.find(widgetId);
		}
		
		public function getRegistedWidgets():Array
		{
			var widgetNames:Array = this._widgetMap.getKeySet();
			var widgets:Array = [];
			for each(var wName:String in widgetNames){
				var widget:IBaseWidget = this._widgetMap.find(wName);
				widgets.push(widget);
			}
			return widgets;
		}
	}
}